<?php
class Admin_ConfigsController extends Zend_Controller_Action
{	
    public function init() {
        if (Zend_Auth::getInstance ( 'admin' )->setStorage ( new Zend_Auth_Storage_Session ( 'admin' ) )->hasIdentity () == false) {
			$this->_helper->getHelper ( 'Redirector' )->gotoUrl ( "admin/login" );
		} 
    }
    public function indexAction()
    {
      $this->view->title = "Config";	
    	try {
               $config = new Vina_Model_Configs();
               $form                   = new Admin_Form_Config();

               $data = $config->find(1)->toArray();
               $form->populate($data);
               if ($this->_request->isPost()) {
                    $formData = $this->_request->getPost();
                    if ($form->isValid($formData)) {
                       $dataInsert = $form->getValues();
                       $config->setId(1);
                       if($dataInsert['banner'] != NULL){
                       $config->setBanner("upload/".$dataInsert['banner']);
                       }
                       if($dataInsert['logo'] != NULL){
                       $config->setLogo("upload/".$dataInsert['logo']);
                       }
                       $config->setTitle($formData['title']);
                       $config->setMeta($formData['meta']);
                       $config->setEmail($formData['email']);
                       $config->setPhone($formData['phone']);
                       $config->setMobile($formData['mobile']);
                       $config->setMap($formData['map']);
                       $config->setVideo($formData['video']);
                       $config->setFacebook($formData['facebook']);
                       $config->setTwiter($formData['twiter']);
                       $config->setGoogle($formData['google']);
                       $config->setAddress($formData['address']);
                       $config->setCompanyName($formData['company_name']);
                       $config->save();
                       $this->_redirect('/admin/configs');
                    }
                }
               //set view
               $this->view->form       = $form;
         }catch(Exception $ex){
            echo "<pre>";
            print_r($ex->getMessage());
        }
    
    }
    	
}
